package org.jetlinks.pro.notify.configuration;

import org.jetlinks.core.event.EventBus;
import org.jetlinks.pro.notify.*;
import org.jetlinks.pro.notify.template.TemplateManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(StaticNotifyProperties.class)
public class NotifierAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(NotifyConfigManager.class)
    public StaticNotifyConfigManager staticNotifyConfigManager(StaticNotifyProperties properties) {
        return new StaticNotifyConfigManager(properties);
    }

    @Bean
    @ConditionalOnMissingBean(TemplateManager.class)
    public StaticTemplateManager staticTemplateManager(StaticNotifyProperties properties,
                                                       EventBus eventBus) {
        return new StaticTemplateManager(properties, eventBus);
    }

    @Bean
    @ConditionalOnMissingBean(NotifierManager.class)
    public DefaultNotifierManager notifierManager(EventBus eventBus,
                                                  NotifyConfigManager configManager) {
        return new DefaultNotifierManager(eventBus, configManager);
    }

}
